﻿using BaiTu.Framework.Core.StartupTask;
using BaiTu.Framework.Core.TypeFinder;
using BaiTu.IOCServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace BaiTu.Config.StartupTask
{
    public class StartupTask : IStartupTask
    {

        public void Execute()
        {
            var typeFinder = EngineContext.Current.Resolve<ITypeFinder>();

            var configList = typeFinder.FindClassesOfType<IConfig>();
            if (configList != null && configList.Count() > 0)
            {
                foreach (var item in configList)
                {
                    var configType = (IConfig)Activator.CreateInstance(item);
                    if (configType != null)
                    {
                        configType.SaveConfigInitialize();
                    }
                }
            }

        }

        public int Order
        {
            get { return 100; }
        }
    }
}
